<?php
include_once 'entity/Module.php';
class Administrator_Module_Grid extends BaseGrid{
	protected $seachEntity = array(
		Module::ID,
		Module::NAME
	);
	
	public function init(){
		$this->headerLb[Module::ID] = 'ID'; 
		$this->headerLb[Module::NAME] = 'Tên';
		$this->headerLb[Module::DISPLAY] = 'Hiển thị';
		$this->headerLb[Module::ROWVERSION] = 'Version';
	}
	public function _preRender(){
		$link = $this->getEditLink();
		$this->cols = array(
			BaseGrid::COL_ORDINAL => array(BaseGrid::TYPE_ORDINAL),
			BaseGrid::COL_CHECKBOX => array(BaseGrid::TYPE_CHECKBOX),
			Module::NAME => array(Module::NAME,BaseGrid::TYPE_LINK,$link,array(Module::ID)),
			Module::DISPLAY => array(Module::DISPLAY,BaseGrid::TYPE_TEXT),
			Module::LASTUPDATEBY => array(Module::LASTUPDATENAME,BaseGrid::TYPE_TEXT),
			Module::LASTUPDATETIME => array(Module::LASTUPDATETIME,BaseGrid::TYPE_TEXT),
			Module::ROWVERSION => array(Module::ROWVERSION,BaseGrid::TYPE_TEXT),
			Module::STATUS => array(Module::STATUSNAME,BaseGrid::TYPE_TEXT),
			Module::ID => array(Module::ID,BaseGrid::TYPE_TEXT)
		);
	}
	public function searchQuery(){
		$sql = 'SELECT t.' .Module::ID.',';
		$sql .= 't.' .Module::DISPLAY.',';
		$sql .= 't.' .Module::NAME.',';
		$sql .= 't.' .Module::LASTUPDATETIME.',';
		$sql .= 't.' .Module::ROWVERSION.',';
		$sql .= 'u.name as '.Module::LASTUPDATENAME.',';
		$sql .= 's.name as '.Module::STATUSNAME;
		$sql .= ' FROM module as t';
		
		$sql .= ' LEFT JOIN usersystem as u';
		$sql .= ' ON t.lastupdateby = u.id';
		
		$sql .= ' LEFT JOIN status as s';
		$sql .= ' ON t.status = s.id';
		
		$where = " WHERE ";
		
		if(isset($this->searchCondition['Module_id']) && $this->searchCondition['Module_id'] != "")
		$where .= ' t.id="'.$this->searchCondition['Module_id'].'" and';
		
		if(isset($this->searchCondition['Module_name']) && $this->searchCondition['Module_name'] != "")
		$where .= ' t.name like"%'.$this->searchCondition['Module_name'].'%" and';
		
		if(isset($this->searchCondition['Module_status']) && $this->searchCondition['Module_status'] != "")
		$where .= ' t.status="'.$this->searchCondition['Module_status'].'" and';
		
		$where .= ' 1 = 1';
		$sql .= $where;
		return $sql;
	}
}